package com.pjj.projectservice.controller;

import com.pjj.projectservice.entity.Project;
import com.pjj.projectservice.entity.Team;
import com.pjj.projectservice.service.impl.ProjectServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author 76004
 * @apiNote 立项
 * @date 2023/2/12 23:25
 */
@RestController
@RequestMapping("/project")
public class ProjectController {
    @Autowired
    private ProjectServiceImpl projectService;

    @DeleteMapping("/deleteProjectById")
    @ApiOperation(value = "删除项目")
    public Object deleteProject(long projectId){
        return projectService.deleteById(projectId);
    }

    @ApiOperation(value = "更新项目")
    @PutMapping("/updateProject")
    public Object updateProject(@RequestBody Project project){
        return projectService.updateProject(project);
    }

    @ApiOperation(value = "查询所有项目")
    @GetMapping("/selectAll")
    public Object selectAll(int pageNum, int pageSize){
        return projectService.selectPage(pageNum,pageSize);
    }

    @ApiOperation(value = "查询项目成员")
    @GetMapping("/selectProjectMember")
    public Object selectProjectMember(long id){
        return projectService.selectProjectMemberId(id);
    }

    @ApiOperation(value = "添加项目成员")
    @PostMapping("/insertProjectMember")
    public Object addTeammate(@RequestBody Team team){
        return projectService.addProjectMember(team);
    }

    @ApiOperation(value = "查询某一用户参与的项目")
    @GetMapping("/selectProjectByUserId")
    public Object selectProjectByUserId(String userId){
        return projectService.selectProjectByUserId(userId);
    }

    @ApiOperation(value = "查询项目数量")
    @GetMapping("/selectProjectCount")
    public Object selectProjectCount(){
        return projectService.selectProjectCount();
    }

    @ApiOperation(value = "高权限人员指定立项")
    @PostMapping("/makeProjectByHighAuthority")
    public Map<String,Object> makeProjectByHighAuthority(@RequestBody Project project){
        return projectService.makeProjectByHighAuthority(project);
    }

    @ApiOperation(value = "组长立项")
    @PostMapping("/makeProjectByLeader")
    public Map<String,Object> makeProjectByLeader(@RequestBody Project project){
        return projectService.makeProjectByLeader(project);
    }

    @ApiOperation(value = "开启项目code加入并生成code")
    @GetMapping("/makeProjectAccessCode")
    public Map<String,Object> makeProjectAccessCode(long projectId,long timeout){
        return projectService.makeProjectAccessCode(projectId,timeout);
    }

    @ApiOperation(value = "关闭项目code加入")
    @GetMapping("/makeNoProjectAccessCode")
    public Map<String,Object>makeNoProjectAccessCode(Long projectId){
        return projectService.makeNoProjectAccessCode(projectId);
    }

    @ApiOperation(value = "用户输入code加入项目")
    @PutMapping("/joinProjectByCode")
    public Map<String,Object>joinProjectByCode(String userId,String code){
        return projectService.joinProjectByCode(userId,code);
    }

    @ApiOperation(value = "将某用户从某项目中移除")
    @DeleteMapping("/removeMemberById")
    public Map<String,Object> removeMemberById(String removeUserId, Long projectId, String requestUserId){
        return projectService.removeMemberById(removeUserId,projectId,requestUserId);
    }

    @ApiOperation(value = "用户主动退出项目")
    @DeleteMapping("/exitProjectById")
    public Map<String,Object> exitProjectById(String userId, Long projectId){
        return projectService.exitProjectById(userId,projectId);
    }





}
